export default {

}

/**
 * 是否为群消息
 * @param {*} message 
 * @returns 
 */
export function is_group_message(message) {
    return message["group_id"] !== undefined;
}

/**
 * 获取群号
 * @param {*} message 
 * @returns 
 */
export function get_group_id(message) {
    return message["group_id"];
}

/**
 * 是否为指定群号
 * @param {*} message
 * @param {*} group_id
 * @returns
 */
export function has_group_id(message, group_id) {
    return message["group_id"] === group_id;
}

/**
 * 发送群消息(http 文本)
 */
export function send_http_group_text_message(group_id, message) {
    let send_data = {
        "group_id": group_id,
        "message": [
            {
                "type": "text",
                "data": {
                    "text": message
                }
            }
        ]
    };
    send_http_request("send_group_msg", JSON.stringify(send_data));
}
/**
 * 发送群消息(http json)
 */
export function send_http_group_json_message(group_id, message) {
    let send_data = {
        "group_id": group_id,
        "message": message
    };
    send_http_request("send_group_msg", JSON.stringify(send_data));
}

/**
 * 发送群消息
 */
export function send_ws_group_text_message(group_id, message) {
    let send_data = {
        "action": "send_group_msg",
        "params": {
            "group_id": group_id,
            "message": [
                {
                    "type": "text",
                    "data": {
                        "text": message
                    }
                }
            ]
        },
        "echo": ""
    };
    _websocket_.send_ws_message(one_bot_ws_client_id, JSON.stringify(send_data));
}

/**
 * 发送群消息
 */
export function send_ws_group_json_message(group_id, message) {
    let send_data = {
        "action": "send_group_msg",
        "params": {
            "group_id": group_id,
            "message": message
        },
        "echo": ""
    };
    _websocket_.send_ws_message(one_bot_ws_client_id, JSON.stringify(send_data));
}

function send_http_request(path, body) {
    _http_.ignore_async_post(`${one_bot_http_address}/${path}`, one_bot_headers, body);
}

/**
 * 发送at全体成员的群消息
 */
export function send_ws_group_at_all_text_message(group_id, message) {
    let send_data = {
        "action": "send_group_msg",
        "params": {
            "group_id": group_id,
            "message": [
                {
                    "type": "at",
                    "data": {
                        "qq": "all"
                    }
                },
                {
                    "type": "text",
                    "data": {
                        "text": message
                    }
                }
            ]
        },
        "echo": ""
    };
    _websocket_.send_ws_message(one_bot_ws_client_id, JSON.stringify(send_data));
}